// CPU_usage.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>

void ThreadFunc()
{
	while(1)
	{
		for (int i=0;i<100;i++)
		{

		}
		Sleep(100);
	}

}


int main()
{
	int busyTime = 3; // 10 ms
	int idleTime = busyTime;
	DWORD startTime = 0;
	for (int k=0;k<100;k++)
	{
		CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadFunc,NULL,0,NULL);
	}
	SetProcessAffinityMask(
		GetCurrentProcess(),
		0x00000001        //cpu mask
		);
	while(true)
	{
		startTime = GetTickCount();
		// busy loop
		while((GetTickCount()- startTime) <= busyTime);

			// idle loop
			Sleep(idleTime);
	}
	return 0;
}


